// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PACKET_HANDLE_H
#define PACKET_HANDLE_H

#include "Communication/StreamParse/StreamParser.h"
#include "Communication/MsgFragment/MsgReassemble.h"
#include "Communication/Include/CommApi.h"

class PacketHandle : public ServiceHandle {
public:
    /**
     * @功能描述：PacketHandle构造函数
     * @参数 [in] type：数据包类型
     * @参数 [in] hook：钩子函数
     * @参数 [in] isSingleFragment：是否单包（不分片）
     */
    PacketHandle(VMIMsgType type, RENDER_SERVER_HANDLE_HOOK hook, bool isSingleFragment);

    /**
     * @功能描述：删除PacketHandle默认构造函数
     */
    PacketHandle() = delete;

    /**
     * @功能描述：PacketHandle析构函数
     */
    ~PacketHandle() override;

    /**
     * @功能描述：包数据处理函数，将消息存储到队列中
     * @参数 [in] packet：包的指针
     */
    void Handle(const VmiBuffer& packet) override;

    /**
     * @功能描述：清空包队列
     */
    virtual void ClearQueue();

protected:
    MsgReassemble m_msgReassemble{m_type};
    VMIMsgType m_type = VMIMsgType::Invalid;
    RENDER_SERVER_HANDLE_HOOK m_hook = nullptr;
};
#endif
